package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

import com.google.zxing.Result;
import com.king.zxing.CameraScan;
import com.king.zxing.CaptureActivity;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityScanQrBinding;
import flc.ast.utils.Content;
import stark.common.basic.utils.StatusBarUtils;
import stark.common.basic.utils.StkPermissionHelper;

public class ScanQrActivity extends CaptureActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtils.with(this).init();
        StatusBarUtils.setSystemStatusTextColor(false, this);
        ImageView ivBack = findViewById(R.id.ivFileScanBack);
        ivBack.setOnClickListener(v -> onBackPressed());
    }

    @Override
    public void initCameraScan() {
        super.initCameraScan();
    }

    @Override
    public void startCamera() {
        super.startCamera();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_scan_qr;
    }

    @Override
    public int getViewfinderViewId() {
        return R.id.viewfinderView;
    }

    @Override
    public int getPreviewViewId() {
        return R.id.previewView;
    }

    @Override
    public int getFlashlightId() {
        return 0;
    }

    @Override
    public CameraScan getCameraScan() {
        return super.getCameraScan();
    }

    @Override
    public boolean onScanResultCallback(Result result) {
        Intent intent = new Intent();
        intent.putExtra(Content.result, result.getText());
        setResult(RESULT_OK, intent);
        finish();
        return false;
    }
}